<?php
	
	// Session
	session_start();
	
	// Nese vizitori eshte i identifikuar
	if (!isset($_SESSION['user_id'])) {
		header("Location: login.php");
	}
	
	// Integrimi i skedave sistemore
    include('../include/functions.inc.php');
	include('../include/template.class.php');
	
	// Project
	$PROJECT = setProject();
	
	
	// Ndyshoret primare
	define('TPL','../include/styles/'.$PROJECT['style'].'/members/userdescript.html');
	define('UID',$_SESSION['user_id']);
	define('FILENAME',basename($_SERVER["PHP_SELF"]));
	
	
	// Connection
	dbOpen("comunity");
	
	
	// Inicializimi i shablonave
	$tmp = new Template(TPL,$PROJECT['lang']);
	
	
	// Te dhenat e vizitorit
	$USER = mysql_fetch_assoc(mysql_query("SELECT description FROM authors WHERE id = '".UID."'"));
	
	
	// Nese forma akoma nuk eshte aplikuar
	if (!isset($_POST['send'])) $_POST = $USER;

	
	// LABELS
	$tmp->setLabels();
	
	// MENUES
	$tmp->setContent("CATEGORY",$tmp->menu("category","../members")); 
	$tmp->setContent("MYMENU",$tmp->menu("mymenu","userprofil.php"));
	$tmp->setContent("FOOTMENU",$tmp->menu("foot"));
	$tmp->setContent("MYPROFIL",$tmp->menu("myprofil",FILENAME));
	
	
	// ACCORDIONS
	$tmp->setContent("USERPROFIL",$tmp->xmlContent("userprofil","help.xml"));
	$tmp->setContent("USERDESCRIPT",$tmp->xmlContent("userdescript","help.xml"));
	$tmp->setContent("USERIMAGE",$tmp->xmlContent("userimage","help.xml"));

	
	
	// Aplikimi i formes
	if(isset($_POST['send'])) {
		
		// NULL PROFESSION
		if(empty($_POST['description']))
			$ERROR['description'] = "null";
			
		
		// Nese nuk ka asnje gabim
		if(empty($ERROR)) {
			
			// Arkivimi i vlerave
			$query = "UPDATE authors SET description = '".$_POST['description']."' WHERE id = '".UID."' ";
			
			// Nese te dhenat aktualizohen, trego splash porosin
			if(mysql_query($query)) {
				
				// Rilexo faqen me porosin per sukses
				header('Location: userdescript.php?splash=userupdate'); 
				exit;
			}
			else {
				
				// Rilexo faqen me porosin per sukses
				header('Location: userdescript.php?splash=busy'); 
				exit;
			}
		}
	}
	
	
	// Convert POST and ERROR vars in Form
	$tmp->setForm($_POST,$ERROR);

	
	// Dhe cdo gje ka nje fund, trego faqen						  
	echo $tmp->vorlage;
	
?>